package com.soft.javase.exam;

import java.util.Arrays;
import java.util.HashSet;
import java.util.Random;

/**
 * @author yzg
 * @desc TODO
 * @date 2025/5/17
 */
public class HashSetDemo {
    public static void main(String[] args) {
        String[] strArray = new String[200];
        HashSet<String> set = new HashSet<>();
        HashSet<String> count = new HashSet<>();

        String str = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789!@#$%^&*()_+-=[]{}|;:',.<>?";
        Random random = new Random();

        for (int i = 0; i < strArray.length; i++) {
            char c1 = str.charAt(random.nextInt(str.length()));
            char c2 = str.charAt(random.nextInt(str.length()));
            strArray[i] ="" + c1 + c2;

            if (!set.add(strArray[i])) {
                count.add(strArray[i]);
            }
        }

        System.out.println("生成的字符串数组："+ Arrays.toString(strArray));
        System.out.println("重复字符串数量: " + count.size());
        System.out.println("重复的字符串: "+count);

    }
}
